<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <link href="../css/swiper.min.css" rel="stylesheet"/>
    <style>
    .x-ico-month2 .el-input__inner{
      border: 0;
      font-size: 1rem;
      text-align: center;
    }.el-input__prefix{
      display: none;
    }.x-has-bor .el-input__inner{
      border: 1px solid #dcdfe6;
      padding: 0 .4rem;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <!--  -->
      <div class="x-ico-month x-ico-month2" style="box-shadow:none;margin:1rem;border-radius:.4rem;">
        <el-date-picker v-model="cardsmonth" type="date" placeholder="" @change="getdata" format="yyyy 年 MM 月 dd 日" value-format="yyyyMMdd" :editable="notkey"></el-date-picker>
      </div>
      <!--  -->
      <div class="x-workforce-tabs swiper-container" style="margin:1rem">
        <div class="swiper-wrapper">
          <div class="swiper-slide x-workforce-items" v-for="(item,index) in formheaderdata" :key="item.id" @click="changetab(index,item.id)" :class="{active:curId==index}">{{item.title}}</div>
        </div>
      </div>
      <!--  -->
      <div class="x-pro-list" v-for="(itemb,indexb) in formdata" :key="itemb.key" v-if="formdata!=''">
        <div class="x-pro-top">工作站：{{itemb.title}}</div>
        <el-table :data="itemb.list" @cell-click="">
          <el-table-column label="排班时间" width="120" fixed>
            <template slot-scope="scope">
              {{scope.row.before_date1}}-{{scope.row.before_date2}}
            </template>
          </el-table-column>
          <el-table-column label="员工" width="">
            <template slot-scope="scope">
              {{scope.row.username}}
            </template>
          </el-table-column>
          <el-table-column label="工时" width="">
            <template slot-scope="scope">
              {{scope.row.hour}}h
            </template>
          </el-table-column>
          <el-table-column label="工时确认" width="120"  v-if="personlimits!='0'">
            <template slot-scope="scope">
              <el-button type="primary" v-if="scope.row.is_confirm=='0'" @click="workok(scope.row.id,scope.row.username)" size="mini">点击确认</el-button>
              <div v-if="scope.row.is_confirm=='1'" size="mini" class="x-text-g">已完成</div>
              <div v-if="scope.row.is_confirm=='2'" size="mini" class="x-text-r">未完成</div>
            </template>
          </el-table-column>
          <el-table-column label="确认人" width="">
            <template slot-scope="scope">
              {{scope.row.confirm_member}}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120"  v-if="personlimits!='0'">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="edittime(scope.row.id,scope.row.username)"  v-if="scope.row.is_confirm=='0'">编辑</el-button>
              <el-button type="text" size="mini" v-if="scope.row.workid=='0'" @click="remorework(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="x-pro-addbox" @click="addworktime(itemb.id)" v-if="personlimits!='0'"><span class="x-pro-addicon"></span>继续添加</div>
      </div>
      <!-- 空空如也 -->
      <div class="x-nothing" v-if="formdata==''">空空如也</div>
      <!--  -->
      <el-dialog :title="' '+edittimename + ' '" :visible.sync="edittimetoast" width="90%" center="true" close-on-click-modal="false" show-close="false">
        <div class="x-pro-row">
          <div class="x-pro-label">排班时间：</div>
          <div class="x-pro-input x-has-bor" style="display:flex;">
            <el-time-select placeholder="起始时间" v-model="deittimestart" :picker-options="{start: '04:00',step: '00:30',end: '24:00'}" :editable="notkey"></el-time-select>
            <div style="align-self:center;">&nbsp;-&nbsp;</div>
            <el-time-select placeholder="结束时间" v-model="deittimeend" :picker-options="{start: '04:00',step: '00:30',end: '24:00',minTime: deittimestart}" :editable="notkey"></el-time-select>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="edittimetoast = false">取 消</el-button>
          <el-button type="primary" @click="okgettime">确 定</el-button>
        </span>
      </el-dialog>
      <!--  -->
      <el-dialog title="添加排班" :visible.sync="addworktimetoast" width="90%" center="true" close-on-click-modal="false" show-close="false">
        <div class="x-pro-row">
          <div class="x-pro-label">排班时间：</div>
          <div class="x-pro-input x-has-bor" style="display:flex;">
            <el-time-select placeholder="起始时间" v-model="addworktimetoaststart" :picker-options="{start: '04:00',step: '00:30',end: '24:00'}" :editable="notkey"></el-time-select>
            <div style="align-self:center;">&nbsp;-&nbsp;</div>
            <el-time-select placeholder="结束时间" v-model="addworktimetoastend" :picker-options="{start: '04:00',step: '00:30',end: '24:00',minTime: addworktimetoaststart}"  :editable="notkey"></el-time-select>
          </div>
        </div>
        <div class="x-pro-row">
          <div class="x-pro-label">排班员工：</div>
          <div class="x-pro-input">
            <el-select v-model="addworktimeperson" placeholder="请选择">
              <el-option v-for="item in persondata" :key="item.id" :label="item.username" :value="item.id"></el-option>
            </el-select>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="addworktimetoast = false">取 消</el-button>
          <el-button type="primary" @click="okgettimeper">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
  <script type="text/javascript" src="../script/swiper.min.js"></script>
	<script>
apiready = function () {



    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          cardsmonth:'',
          formheaderdata:'',
          curId:0,
          formdata:'',
          personlimits:'',
          edittimetoast:false,
          edittimename:'',
          deittimestart:'',
          deittimeend:'',
          edittimeid:'',
          addworktimeid:'',
          addworktimetoast:false,
          addworktimetoaststart:'',
          addworktimetoastend:'',
          addworktimeperson:'',
          persondata:'',
          notkey:false,

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        var day = date.getDate()
        if(month<10){
          month = '' + 0 + month;
        }
        if(day<10){
          day = '' + 0 + day;
        }
        var toMonth = '' + year +  month +  day;
        that.cardsmonth = toMonth;
        that.getpersondata()
        that.getdata()
      },
      methods: {
        //工时确认
        workok:function(id,name){
          var that = this;
          api.actionSheet({
              title: '请确认“'+ name + '”是否完成排班',
              cancelTitle: '取消',
              buttons: ['已完成', '未完成']
          }, function(ret, err) {
              var index = ret.buttonIndex;
              console.log(index);// 1 2
              if(index=='1'){
                that.settake(id,index)
              }else if(index=='2'){
                that.settake(id,index)
              }

          });
        },
        //工时确认 提交
        settake:function(id,index){
          let that=this;
          api.ajax({
            url:baseurl+'api/workforce/confirm',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:id,
                type:index
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.getdata()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //删除
        remorework:function(id){
          let that = this;
          api.confirm({
            title: '操作提示',
            msg: '确定要删除吗？',
            buttons: ['确定','取消']
          }, function(ret, err) {
            var index = ret.buttonIndex;
            if(index == 1){
              //删除
              that.remoreworkajax(id)
            }
          });
        },
        //删除 提交
        remoreworkajax:function(id){
          let that=this;
          api.ajax({
            url:baseurl+'api/workforce/delDate',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:id
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
                that.getdata()
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //人员列表
        getpersondata:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/person/list',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              // console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.persondata = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //添加 提交
        okgettimeper:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/workforce/addDate',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                areaid:that.tabsid,
                wsid:that.addworktimeid,
                in_date:that.cardsmonth,
                date1:that.addworktimetoaststart,
                date2:that.addworktimetoastend,
                memberid:that.addworktimeperson
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.addworktimetoast = false;
                that.getdata()
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //添加
        addworktime:function(id){ //工作站id
          var that = this;
          that.addworktimeid = id;
          that.addworktimetoaststart = '';
          that.addworktimetoastend = '';
          that.addworktimeperson = '';
          that.addworktimetoast = true;
        },
        //编辑工时 提交
        okgettime:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/workforce/editDate',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:that.edittimeid,
                date1:that.deittimestart,
                date2:that.deittimeend
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.edittimetoast = false;
                that.getdata()

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //编辑工时
        edittime:function(id,name){
          var that = this;
          that.edittimeid = id;
          that.edittimetoast = true;
          that.edittimename = name;

          that.deittimestart = '';
          that.deittimeend = '';


        },
        //切换选项卡 表格数据
        changetab:function(index,id){
          var that = this;
          that.curId = index;
          that.tabsid = id;
          that.getdata()
        },
        //
        getdata:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/workforce/worktime',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                areaid:that.tabsid,
                date:that.cardsmonth
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                  that.formheaderdata = ret.data.area;
                  that.personlimits = ret.data.access;//权限 0没有 1有
                  // that.datalimits = ret.data.is_edit;
                  // if(that.personlimits=='1'&&that.datalimits=='1'){//1有权限 0没有
                  //     console.log('有权限');
                  //     that.isfromindex = false;
                  // }else{
                  //   that.isfromindex = true;
                  // }
                  that.tabsid = ret.data.area[0].id;
                  that.formdata = ret.data.list;
                  // that.money = ret.data.predict;
                  that.$nextTick(function(){
                    var mySwiper = new Swiper('.swiper-container',{
                      freeMode: true,
                      loop:false,//设置 active slide 居中后，会有左右留白现象，添加此会让未尾的导航补齐前后空白
                      slideToClickedSlide: true,//设置为true则点击slide会过渡到这个slide。
                      slidesPerView: 2.5,
                      centeredSlides: false,//设定为true时，active slide会居中，而不是默认状态下的居左。
                      spaceBetween: 10,//slide之间设置距离
                      slidesOffsetBefore: 0,//设定slide与左边框的预设偏移量
                      slidesOffsetAfter: 0,//设定slide与右边框的预设偏移量

                    });

                  });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}


	</script>
</body>
</html>
